package com.xmut.mall.product.searchparam;

import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmut.mall.product.vo.PageVO;
import lombok.Data;

@Data
public class SpuSearchParam extends PageVO {
    private static final long serialVersionUID = 2544015852728566887L;

    /**
     * spu的名称
     */
    private String spuName;

    /**
     * spu的Id
     */
    private Long spuId;

    /**
     * 分类的id
     */
    private Long cateLogId;

    /**
     * 品牌Id
     */
    private Long brandId;

    /**
     * 审核状态
     */
    private Integer reviewStatus;

    /**
     * 上架状态
     */
    private Integer publishStatus;

    // 分页相关
    /**
     * 当前页数
     */
    private Integer pageNumber;

    /**
     * 页面大小
     */
    private Integer pageSize;

    /**
     * 默认排序字段
     */
    private String sort;

    /**
     * 默认排序方式
     */
    private String order;

    /**
     * 组装参数
     * @param <T>
     * @return
     */
    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();

        if (CharSequenceUtil.isNotEmpty(spuName)){
            queryWrapper.like("spu.spu_name",spuName);
        }

        if (spuId!=null){
            queryWrapper.eq("spu.id",spuId);
        }

        if (cateLogId!=null){
            queryWrapper.eq("spu.catalog_id",cateLogId);
        }

        if (brandId!=null){
            queryWrapper.eq("spu.brand_id",brandId);
        }

        if (reviewStatus!=null){
            queryWrapper.eq("spu.review_status",reviewStatus);
        }

        if (publishStatus!=null){
            queryWrapper.eq("spu.publish_status",publishStatus);
        }

        return queryWrapper;
    }
}
